home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 082 (1989-02-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 082 (1989-02-15)(Ossowski, Stefan)(DE)(PD).adf / Milben / virus.c < prev    next >
C/C++ Source or Header  |  1988-11-11  |  6KB  |  273 lines

  1. /*
  2.  
  3.      Milben...
  4.  
  5.      von Guido Appenzeller - Landessternwarte - 6900 Heidelberg
  6.  
  7.       Maschienensprache von Guido Appenzeller & Chris Emmerich
  8.  
  9.      (c) all Rights reserved.
  10.  
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <functions.h>
  15. #include <stdio.h>
  16. #include <graphics/gfxbase.h>
  17. #include <intuition/intuitionbase.h>
  18. #include <intuition/intuition.h>
  19.  
  20. #define MAXNUMBER    200
  21.  
  22. struct IntuitionBase *IntuitionBase;
  23. struct GfxBase       *GfxBase;
  24. struct RastPort      *rp;
  25. UBYTE  *plane0,*plane1;
  26.  
  27. int   x1,y1;
  28.  
  29. long x[MAXNUMBER];
  30. long y[MAXNUMBER];
  31. int hunger[MAXNUMBER];
  32. int futter[MAXNUMBER];
  33.  
  34. int nummer = 200;
  35. int hungertod = 80;
  36. int nachwuchs = 15;
  37. int stoppos   = 3;
  38.  
  39. int anzahl=1;
  40.  
  41. int f,t,a,xx,yy;
  42.  
  43. BYTE  cflag=2;
  44.  
  45. long mtime;
  46.  
  47. main(argc,argv)
  48. int   argc;
  49. char  *argv[];
  50. {
  51.  
  52. if (argc == 1)
  53. {
  54. printf(">>> MultiVirus <<<\n\n  (c) by Guido Appenzeller and Chris Emmerich\n");
  55. printf("\nFormat:  VIRUS [Verzoegerung Anzahl Hunger Nachwuchs StopPos]] [-L]\n");
  56. }
  57. else if ( *argv[1] != 0 )
  58.    {
  59.       for(t=1;t!=argc;t++)
  60.          {
  61.             if(*argv[t]=='-') cflag = ( *(++argv[t])!='L' );
  62.             else
  63.                {
  64.                   if( t == 1 ) mtime = atol( argv[1] );
  65.                   if( t == 2 ) nummer = atoi( argv[2] );
  66.                   if( t == 3 ) hungertod = atoi( argv[3] );
  67.                   if( t == 4 ) nachwuchs = atoi( argv[4] );
  68.                   if( t == 5 ) stoppos   = atoi( argv[5] );
  69.                }
  70.          }
  71.    }
  72.  
  73. if (nummer > MAXNUMBER-2 ) nummer = MAXNUMBER-2;
  74.  
  75. /* --- Intuition und Graphics oeffnen                 --- */
  76.  
  77. if((IntuitionBase = (struct IntuitionBase *)
  78.                   OpenLibrary("intuition.library",0L)) == NULL )
  79. {  printf("Intuition nicht gefunden !\n");
  80.    exit(FALSE);           }
  81.  
  82. if((GfxBase = (struct GfxBase *)
  83.                   OpenLibrary("graphics.library",0L)) == NULL )
  84. {  printf("Grafix-Library nicht gefunden !\n");
  85.    CloseLibrary(IntuitionBase);
  86.    exit(FALSE);           }
  87.  
  88.  
  89.  
  90. /* --- Initialisieren -------------------------- */
  91.  
  92. rp = &( IntuitionBase->ActiveScreen->RastPort );
  93. plane0 = rp->BitMap->Planes[0];
  94. plane1 = rp->BitMap->Planes[1];
  95. x[0] = 320; y[0] = 128; hunger[0] = 100; futter[0] = 0;
  96.  
  97. Delay(mtime);
  98.  
  99. /* --- Bewegen ------------------------------------- */
  100.  
  101. while( (IntuitionBase->ActiveScreen->MouseX) != stoppos )
  102. {
  103.    for(t=0;t<anzahl;t++)
  104.    {
  105.    SetAPen(rp,0L);
  106.    WritePixel(rp,x[t],y[t]);
  107.    xx = x[t];yy = y[t];
  108.    a = rand();
  109.    x1=x[t];y1=y[t];
  110. #asm
  111.       movem.l  d0-d7/a0-a6,-(sp)
  112.  
  113.       clr.w    d0
  114.       clr.w    _f
  115.       move.w   _xx,d0
  116.       move.w   _yy,d1
  117.       addq.w   #1,d0
  118.       jsr      ReadPixel
  119.       subq.b   #1,d3
  120.       bne      links
  121.       move.w   #1,_a
  122.       bset     #0,_f+1
  123.       bra      Weg1
  124.  
  125. links move.w   _xx,d0
  126.       move.w   _yy,d1
  127.       subq.w   #1,d0
  128.       jsr      ReadPixel
  129.       subq.b   #1,d3
  130.       bne      hoch
  131.       move.w   #2,_a
  132.       bset     #0,_f+1
  133.       bra      Weg1
  134.  
  135. hoch  move.w   _xx,d0
  136.       move.w   _yy,d1
  137.       subq.w   #1,d1
  138.       jsr      ReadPixel
  139.       subq.b   #1,d3
  140.       bne      runte
  141.       move.w   #4,_a
  142.       bset     #0,_f+1
  143.       bra      Weg1
  144.  
  145. runte move.w   _xx,d0
  146.       move.w   _yy,d1
  147.       addq.w   #1,d1
  148.       jsr      ReadPixel
  149.       subq.b   #1,d3
  150.       bne      Weg1
  151.       move.w   #8,_a
  152.       bset     #0,_f+1
  153.  
  154. Weg1  btst     #0,_a+1
  155.       beq      Weg2
  156.       add.w    #1,_xx
  157. Weg2  btst     #1,_a+1
  158.       beq      Weg3
  159.       sub.w    #1,_xx
  160. Weg3  btst     #2,_a+1
  161.       beq      Weg4
  162.       sub.w    #1,_yy
  163. Weg4  btst     #3,_a+1
  164.       beq      WegEn
  165.       add.w    #1,_yy
  166.  
  167. WegEn tst.w    _yy
  168.       bpl      OM
  169.       clr.w    _f
  170. OM    cmp.w    #$100,_yy
  171.       bne      ON
  172.       clr.w    _f
  173. ON    and.w    #$ff,_yy
  174.       tst.w    _xx
  175.       bpl      OL
  176.       move.w   #639,_xx
  177.       clr.w    _f
  178. OL    cmp.w    #640,_xx
  179.       bmi      OK
  180.       clr.w    _xx
  181.       clr.w    _f
  182. OK    move.w   _xx,d0
  183.       move.w   _yy,d1
  184.       jsr      ReadPixel
  185.       move.b   d3,d4
  186.       clr.b    d3
  187.       tst.b    d4
  188.       beq      Blue
  189.       move.b   _cflag,d3
  190. Blue  move.w   _x1,d0
  191.       move.w   _y1,d1
  192.       jsr      WritePixel
  193.       movem.l  (sp)+,d0-d7/a0-a6
  194. #endasm
  195.    x[t]=xx; y[t]=yy;
  196.    SetAPen(rp,3L);
  197.    WritePixel(rp,x[t],y[t]);
  198.  
  199.    if( f ) { hunger[t]=hungertod; futter[t]++;}
  200.    if( anzahl-1 )
  201.       {
  202.          if ( !--hunger[t] )
  203.             {
  204.                SetAPen(rp,2L); WritePixel(rp,x[t],y[t]);
  205.                hunger[t]=hunger[--anzahl];
  206.                futter[t]=futter[anzahl];
  207.                x[t]=x[anzahl]; y[t]=y[anzahl];
  208.             }
  209.       }
  210.    if( ( nummer-2 != anzahl ) && ( futter[t] > nachwuchs ) )
  211.       {
  212.          x[anzahl]=x[t];
  213.          y[anzahl]=y[t];
  214.          hunger[anzahl]=hungertod;
  215.          futter[anzahl++]=0;
  216.          futter[t]=0;
  217.       }
  218.    }
  219.    if(anzahl<2) Delay(1L);
  220. }
  221.  
  222. /* --- Programmende ------------------------- */
  223.  
  224. CloseLibrary(GfxBase);
  225. CloseLibrary(IntuitionBase);
  226.  
  227. exit(TRUE);
  228.  
  229. }
  230.  
  231.  
  232. /* - - - - Eigenes WritePixel() x=d0,y=d1,Plane=a0 640/200 Screen -  */
  233. #asm
  234.  
  235. WritePixel
  236.  
  237.       move.l   _plane0,a0
  238.       move.l   _plane1,a1
  239.       move.w   d0,d2
  240.       lsr.w    #3,d0
  241.       mulu     #80,d1
  242.       add.w    d0,d1
  243.       eor.w    #7,d2
  244.       btst     #0,d3
  245.       beq      hier1
  246.       bset     d2,(a0,d1)
  247. hier1 btst     #1,d3
  248.       beq      hier2
  249.       bset     d2,(a1,d1)
  250. hier2 rts
  251.  
  252. ReadPixel
  253.  
  254.       clr.l    d3
  255.       move.l   _plane0,a0
  256.       move.l   _plane1,a1
  257.       move.w   d0,d2
  258.       lsr.w    #3,d0
  259.       mulu     #80,d1
  260.       add.w    d0,d1
  261.       eor.w    #7,d2
  262.       btst     d2,(a0,d1)
  263.       beq      hier3
  264.       bset     #0,d3
  265. hier3 btst     d2,(a1,d1)
  266.       beq      hier4
  267.       bset     #1,d3
  268. hier4 rts
  269.  
  270. #endasm
  271. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  272.  
  273.